package com.it.mapper;

import com.it.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface EmpMapper {
    //根据ID删除数据
    @Delete("delete from emp where id = #{17}")
    public void delete(Integer id);

    //新增数据
    //对参数进行封装
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
            "    values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    //更新员工
    @Update("update emp set username = #{username},name = #{name},gender = #{gender},image = #{image},job = #{job}," +
            "entrydate = #{entrydate}, dept_id = #{deptId},update_time = #{updateTime} where id = #{id}")
    public void update(Emp emp);

    //查询操作
    @Select("select * from emp where id = #{id}")
    public Emp selectById(Integer id);
    //方案一：
//    @Select("select id,username,password,name,gender,image,job,entrydate,"+
//            "dept_id deptId,create_Time createTime,update_time updateTime from emp where id = #{id}")
//    public Emp getById(Integer id);

    //方案二:通过@Results,@Result注释手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from emp where id = #{id}")
//    public Emp selectById(Integer id);

    //方案三：开启mybatis的驼峰命名自动映射开关---会将a_cloumn这样字段的类名，自动封装驼峰命名（aColumn)的属性名当中

    //模糊查询
//    @Select("select * from emp where name like concat('%',#{name},'%') and gender = #{gender} and entrydate between #{begin} and #{end} order by update_time desc")
//    public List<Emp> list(@Param("name")String name, @Param("gender")Short gender, @Param("begin")LocalDate begin, @Param("end")LocalDate end);

    //动态条件查询
    public List<Emp> list(
            @Param("name") String name,
            @Param("gender") Short gender,
            @Param("begin") LocalDate begin,
            @Param("end") LocalDate end
    );

    //动态更新员工
    public void update2(Emp emp);

    //动态删除员工
    public void delectByIds(List<Integer> ids);
}
